<?php

/**
 * OneClickShipmentRequest.
 *
 * PHP version 8.3
 *
 * @category Class
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 */

/**
 * Amazon Shipping API.
 *
 * The Amazon Shipping API is designed to support outbound shipping use cases both for orders originating on Amazon-owned marketplaces as well as external channels/marketplaces. With these APIs, you can request shipping rates, create shipments, cancel shipments, and track shipments.
 *
 * The version of the OpenAPI document: v2
 * Contact: swa-api-core@amazon.com
 * Generated by: https://openapi-generator.tech
 * Generator version: 7.9.0
 */

/**
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */

namespace SpApi\Model\shipping\v2;

use SpApi\Model\ModelInterface;
use SpApi\ObjectSerializer;

/**
 * OneClickShipmentRequest Class Doc Comment.
 *
 * @category Class
 *
 * @description The request schema for the OneClickShipment operation. When the channelType is not Amazon, shipTo is required and when channelType is Amazon shipTo is ignored.
 *
 * @author   OpenAPI Generator team
 *
 * @see     https://openapi-generator.tech
 *
 * @implements \ArrayAccess<string, mixed>
 */
class OneClickShipmentRequest implements ModelInterface, \ArrayAccess, \JsonSerializable
{
    public const DISCRIMINATOR = null;

    /**
     * The original name of the model.
     */
    protected static string $openAPIModelName = 'OneClickShipmentRequest';

    /**
     * Array of property to type mappings. Used for (de)serialization.
     *
     * @var string[]
     */
    protected static array $openAPITypes = [
        'ship_to' => '\SpApi\Model\shipping\v2\Address',
        'ship_from' => '\SpApi\Model\shipping\v2\Address',
        'return_to' => '\SpApi\Model\shipping\v2\Address',
        'ship_date' => '\DateTime',
        'goods_owner' => '\SpApi\Model\shipping\v2\GoodsOwner',
        'packages' => '\SpApi\Model\shipping\v2\Package[]',
        'value_added_services_details' => '\SpApi\Model\shipping\v2\OneClickShipmentValueAddedService[]',
        'tax_details' => '\SpApi\Model\shipping\v2\TaxDetail[]',
        'channel_details' => '\SpApi\Model\shipping\v2\ChannelDetails',
        'label_specifications' => '\SpApi\Model\shipping\v2\RequestedDocumentSpecification',
        'service_selection' => '\SpApi\Model\shipping\v2\ServiceSelection',
        'shipper_instruction' => '\SpApi\Model\shipping\v2\ShipperInstruction',
        'destination_access_point_details' => '\SpApi\Model\shipping\v2\AccessPointDetails'];

    /**
     * Array of property to format mappings. Used for (de)serialization.
     *
     * @var string[]
     *
     * @phpstan-var array<string, string|null>
     *
     * @psalm-var array<string, string|null>
     */
    protected static array $openAPIFormats = [
        'ship_to' => null,
        'ship_from' => null,
        'return_to' => null,
        'ship_date' => 'date-time',
        'goods_owner' => null,
        'packages' => null,
        'value_added_services_details' => null,
        'tax_details' => null,
        'channel_details' => null,
        'label_specifications' => null,
        'service_selection' => null,
        'shipper_instruction' => null,
        'destination_access_point_details' => null];

    /**
     * Array of nullable properties. Used for (de)serialization.
     *
     * @var bool[]
     */
    protected static array $openAPINullables = [
        'ship_to' => true,
        'ship_from' => false,
        'return_to' => true,
        'ship_date' => true,
        'goods_owner' => true,
        'packages' => false,
        'value_added_services_details' => true,
        'tax_details' => true,
        'channel_details' => false,
        'label_specifications' => false,
        'service_selection' => false,
        'shipper_instruction' => true,
        'destination_access_point_details' => true,
    ];

    /**
     * If a nullable field gets set to null, insert it here.
     *
     * @var bool[]
     */
    protected array $openAPINullablesSetToNull = [];

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     *
     * @var string[]
     */
    protected static array $attributeMap = [
        'ship_to' => 'shipTo',
        'ship_from' => 'shipFrom',
        'return_to' => 'returnTo',
        'ship_date' => 'shipDate',
        'goods_owner' => 'goodsOwner',
        'packages' => 'packages',
        'value_added_services_details' => 'valueAddedServicesDetails',
        'tax_details' => 'taxDetails',
        'channel_details' => 'channelDetails',
        'label_specifications' => 'labelSpecifications',
        'service_selection' => 'serviceSelection',
        'shipper_instruction' => 'shipperInstruction',
        'destination_access_point_details' => 'destinationAccessPointDetails',
    ];

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     *
     * @var string[]
     */
    protected static array $setters = [
        'ship_to' => 'setShipTo',
        'ship_from' => 'setShipFrom',
        'return_to' => 'setReturnTo',
        'ship_date' => 'setShipDate',
        'goods_owner' => 'setGoodsOwner',
        'packages' => 'setPackages',
        'value_added_services_details' => 'setValueAddedServicesDetails',
        'tax_details' => 'setTaxDetails',
        'channel_details' => 'setChannelDetails',
        'label_specifications' => 'setLabelSpecifications',
        'service_selection' => 'setServiceSelection',
        'shipper_instruction' => 'setShipperInstruction',
        'destination_access_point_details' => 'setDestinationAccessPointDetails',
    ];

    /**
     * Array of attributes to getter functions (for serialization of requests).
     *
     * @var string[]
     */
    protected static array $getters = [
        'ship_to' => 'getShipTo',
        'ship_from' => 'getShipFrom',
        'return_to' => 'getReturnTo',
        'ship_date' => 'getShipDate',
        'goods_owner' => 'getGoodsOwner',
        'packages' => 'getPackages',
        'value_added_services_details' => 'getValueAddedServicesDetails',
        'tax_details' => 'getTaxDetails',
        'channel_details' => 'getChannelDetails',
        'label_specifications' => 'getLabelSpecifications',
        'service_selection' => 'getServiceSelection',
        'shipper_instruction' => 'getShipperInstruction',
        'destination_access_point_details' => 'getDestinationAccessPointDetails',
    ];

    /**
     * Associative array for storing property values.
     */
    protected array $container = [];

    /**
     * Constructor.
     *
     * @param null|array $data Associated array of property values
     *                         initializing the model
     */
    public function __construct(?array $data = null)
    {
        $this->setIfExists('ship_to', $data ?? [], null);
        $this->setIfExists('ship_from', $data ?? [], null);
        $this->setIfExists('return_to', $data ?? [], null);
        $this->setIfExists('ship_date', $data ?? [], null);
        $this->setIfExists('goods_owner', $data ?? [], null);
        $this->setIfExists('packages', $data ?? [], null);
        $this->setIfExists('value_added_services_details', $data ?? [], null);
        $this->setIfExists('tax_details', $data ?? [], null);
        $this->setIfExists('channel_details', $data ?? [], null);
        $this->setIfExists('label_specifications', $data ?? [], null);
        $this->setIfExists('service_selection', $data ?? [], null);
        $this->setIfExists('shipper_instruction', $data ?? [], null);
        $this->setIfExists('destination_access_point_details', $data ?? [], null);
    }

    /**
     * Gets the string presentation of the object.
     *
     * @return string
     */
    public function __toString()
    {
        return json_encode(
            ObjectSerializer::sanitizeForSerialization($this),
            JSON_PRETTY_PRINT
        );
    }

    /**
     * Array of property to type mappings. Used for (de)serialization.
     */
    public static function openAPITypes(): array
    {
        return self::$openAPITypes;
    }

    /**
     * Array of property to format mappings. Used for (de)serialization.
     */
    public static function openAPIFormats(): array
    {
        return self::$openAPIFormats;
    }

    /**
     * Checks if a property is nullable.
     */
    public static function isNullable(string $property): bool
    {
        return self::openAPINullables()[$property] ?? false;
    }

    /**
     * Checks if a nullable property is set to null.
     */
    public function isNullableSetToNull(string $property): bool
    {
        return in_array($property, $this->getOpenAPINullablesSetToNull(), true);
    }

    /**
     * Array of attributes where the key is the local name,
     * and the value is the original name.
     */
    public static function attributeMap(): array
    {
        return self::$attributeMap;
    }

    /**
     * Array of attributes to setter functions (for deserialization of responses).
     */
    public static function setters(): array
    {
        return self::$setters;
    }

    /**
     * Array of attributes to getter functions (for serialization of requests).
     */
    public static function getters(): array
    {
        return self::$getters;
    }

    /**
     * The original name of the model.
     */
    public function getModelName(): string
    {
        return self::$openAPIModelName;
    }

    /**
     * Show all the invalid properties with reasons.
     *
     * @return array invalid properties with reasons
     */
    public function listInvalidProperties(): array
    {
        $invalidProperties = [];

        if (null === $this->container['ship_from']) {
            $invalidProperties[] = "'ship_from' can't be null";
        }
        if (null === $this->container['packages']) {
            $invalidProperties[] = "'packages' can't be null";
        }
        if (null === $this->container['channel_details']) {
            $invalidProperties[] = "'channel_details' can't be null";
        }
        if (null === $this->container['label_specifications']) {
            $invalidProperties[] = "'label_specifications' can't be null";
        }
        if (null === $this->container['service_selection']) {
            $invalidProperties[] = "'service_selection' can't be null";
        }

        return $invalidProperties;
    }

    /**
     * Validate all the properties in the model
     * return true if all passed.
     *
     * @return bool True if all properties are valid
     */
    public function valid(): bool
    {
        return 0 === count($this->listInvalidProperties());
    }

    /**
     * Gets ship_to.
     */
    public function getShipTo(): ?Address
    {
        return $this->container['ship_to'];
    }

    /**
     * Sets ship_to.
     *
     * @param null|Address $ship_to ship_to
     */
    public function setShipTo(?Address $ship_to): self
    {
        if (is_null($ship_to)) {
            array_push($this->openAPINullablesSetToNull, 'ship_to');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('ship_to', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['ship_to'] = $ship_to;

        return $this;
    }

    /**
     * Gets ship_from.
     */
    public function getShipFrom(): Address
    {
        return $this->container['ship_from'];
    }

    /**
     * Sets ship_from.
     *
     * @param Address $ship_from ship_from
     */
    public function setShipFrom(Address $ship_from): self
    {
        if (is_null($ship_from)) {
            throw new \InvalidArgumentException('non-nullable ship_from cannot be null');
        }
        $this->container['ship_from'] = $ship_from;

        return $this;
    }

    /**
     * Gets return_to.
     */
    public function getReturnTo(): ?Address
    {
        return $this->container['return_to'];
    }

    /**
     * Sets return_to.
     *
     * @param null|Address $return_to return_to
     */
    public function setReturnTo(?Address $return_to): self
    {
        if (is_null($return_to)) {
            array_push($this->openAPINullablesSetToNull, 'return_to');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('return_to', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['return_to'] = $return_to;

        return $this;
    }

    /**
     * Gets ship_date.
     */
    public function getShipDate(): ?\DateTime
    {
        return $this->container['ship_date'];
    }

    /**
     * Sets ship_date.
     *
     * @param null|\DateTime $ship_date The ship date and time (the requested pickup). This defaults to the current date and time.
     */
    public function setShipDate(?\DateTime $ship_date): self
    {
        if (is_null($ship_date)) {
            array_push($this->openAPINullablesSetToNull, 'ship_date');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('ship_date', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['ship_date'] = $ship_date;

        return $this;
    }

    /**
     * Gets goods_owner.
     */
    public function getGoodsOwner(): ?GoodsOwner
    {
        return $this->container['goods_owner'];
    }

    /**
     * Sets goods_owner.
     *
     * @param null|GoodsOwner $goods_owner goods_owner
     */
    public function setGoodsOwner(?GoodsOwner $goods_owner): self
    {
        if (is_null($goods_owner)) {
            array_push($this->openAPINullablesSetToNull, 'goods_owner');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('goods_owner', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['goods_owner'] = $goods_owner;

        return $this;
    }

    /**
     * Gets packages.
     */
    public function getPackages(): array
    {
        return $this->container['packages'];
    }

    /**
     * Sets packages.
     *
     * @param array $packages a list of packages to be shipped through a shipping service offering
     */
    public function setPackages(array $packages): self
    {
        if (is_null($packages)) {
            throw new \InvalidArgumentException('non-nullable packages cannot be null');
        }
        $this->container['packages'] = $packages;

        return $this;
    }

    /**
     * Gets value_added_services_details.
     */
    public function getValueAddedServicesDetails(): ?array
    {
        return $this->container['value_added_services_details'];
    }

    /**
     * Sets value_added_services_details.
     *
     * @param null|array $value_added_services_details the value-added services to be added to a shipping service purchase
     */
    public function setValueAddedServicesDetails(?array $value_added_services_details): self
    {
        if (is_null($value_added_services_details)) {
            array_push($this->openAPINullablesSetToNull, 'value_added_services_details');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('value_added_services_details', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['value_added_services_details'] = $value_added_services_details;

        return $this;
    }

    /**
     * Gets tax_details.
     */
    public function getTaxDetails(): ?array
    {
        return $this->container['tax_details'];
    }

    /**
     * Sets tax_details.
     *
     * @param null|array $tax_details a list of tax detail information
     */
    public function setTaxDetails(?array $tax_details): self
    {
        if (is_null($tax_details)) {
            array_push($this->openAPINullablesSetToNull, 'tax_details');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('tax_details', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['tax_details'] = $tax_details;

        return $this;
    }

    /**
     * Gets channel_details.
     */
    public function getChannelDetails(): ChannelDetails
    {
        return $this->container['channel_details'];
    }

    /**
     * Sets channel_details.
     *
     * @param ChannelDetails $channel_details channel_details
     */
    public function setChannelDetails(ChannelDetails $channel_details): self
    {
        if (is_null($channel_details)) {
            throw new \InvalidArgumentException('non-nullable channel_details cannot be null');
        }
        $this->container['channel_details'] = $channel_details;

        return $this;
    }

    /**
     * Gets label_specifications.
     */
    public function getLabelSpecifications(): RequestedDocumentSpecification
    {
        return $this->container['label_specifications'];
    }

    /**
     * Sets label_specifications.
     *
     * @param RequestedDocumentSpecification $label_specifications label_specifications
     */
    public function setLabelSpecifications(RequestedDocumentSpecification $label_specifications): self
    {
        if (is_null($label_specifications)) {
            throw new \InvalidArgumentException('non-nullable label_specifications cannot be null');
        }
        $this->container['label_specifications'] = $label_specifications;

        return $this;
    }

    /**
     * Gets service_selection.
     */
    public function getServiceSelection(): ServiceSelection
    {
        return $this->container['service_selection'];
    }

    /**
     * Sets service_selection.
     *
     * @param ServiceSelection $service_selection service_selection
     */
    public function setServiceSelection(ServiceSelection $service_selection): self
    {
        if (is_null($service_selection)) {
            throw new \InvalidArgumentException('non-nullable service_selection cannot be null');
        }
        $this->container['service_selection'] = $service_selection;

        return $this;
    }

    /**
     * Gets shipper_instruction.
     */
    public function getShipperInstruction(): ?ShipperInstruction
    {
        return $this->container['shipper_instruction'];
    }

    /**
     * Sets shipper_instruction.
     *
     * @param null|ShipperInstruction $shipper_instruction shipper_instruction
     */
    public function setShipperInstruction(?ShipperInstruction $shipper_instruction): self
    {
        if (is_null($shipper_instruction)) {
            array_push($this->openAPINullablesSetToNull, 'shipper_instruction');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('shipper_instruction', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['shipper_instruction'] = $shipper_instruction;

        return $this;
    }

    /**
     * Gets destination_access_point_details.
     */
    public function getDestinationAccessPointDetails(): ?AccessPointDetails
    {
        return $this->container['destination_access_point_details'];
    }

    /**
     * Sets destination_access_point_details.
     *
     * @param null|AccessPointDetails $destination_access_point_details destination_access_point_details
     */
    public function setDestinationAccessPointDetails(?AccessPointDetails $destination_access_point_details): self
    {
        if (is_null($destination_access_point_details)) {
            array_push($this->openAPINullablesSetToNull, 'destination_access_point_details');
        } else {
            $nullablesSetToNull = $this->getOpenAPINullablesSetToNull();
            $index = array_search('destination_access_point_details', $nullablesSetToNull);
            if (false !== $index) {
                unset($nullablesSetToNull[$index]);
                $this->setOpenAPINullablesSetToNull($nullablesSetToNull);
            }
        }
        $this->container['destination_access_point_details'] = $destination_access_point_details;

        return $this;
    }

    /**
     * Returns true if offset exists. False otherwise.
     *
     * @param int $offset Offset
     */
    public function offsetExists($offset): bool
    {
        return isset($this->container[$offset]);
    }

    /**
     * Gets offset.
     *
     * @param int $offset Offset
     *
     * @return null|mixed
     */
    #[\ReturnTypeWillChange]
    public function offsetGet($offset): mixed
    {
        return $this->container[$offset] ?? null;
    }

    /**
     * Sets value based on offset.
     *
     * @param null|int $offset Offset
     * @param mixed    $value  Value to be set
     */
    public function offsetSet($offset, mixed $value): void
    {
        if (is_null($offset)) {
            $this->container[] = $value;
        } else {
            $this->container[$offset] = $value;
        }
    }

    /**
     * Unsets offset.
     *
     * @param int $offset Offset
     */
    public function offsetUnset($offset): void
    {
        unset($this->container[$offset]);
    }

    /**
     * Serializes the object to a value that can be serialized natively by json_encode().
     *
     * @see https://www.php.net/manual/en/jsonserializable.jsonserialize.php
     *
     * @return mixed returns data which can be serialized by json_encode(), which is a value
     *               of any type other than a resource
     */
    #[\ReturnTypeWillChange]
    public function jsonSerialize(): mixed
    {
        return ObjectSerializer::sanitizeForSerialization($this);
    }

    /**
     * Gets a header-safe presentation of the object.
     */
    public function toHeaderValue(): string
    {
        return json_encode(ObjectSerializer::sanitizeForSerialization($this));
    }

    /**
     * Array of nullable properties.
     */
    protected static function openAPINullables(): array
    {
        return self::$openAPINullables;
    }

    /**
     * Array of nullable field names deliberately set to null.
     *
     * @return bool[]
     */
    private function getOpenAPINullablesSetToNull(): array
    {
        return $this->openAPINullablesSetToNull;
    }

    /**
     * Setter - Array of nullable field names deliberately set to null.
     *
     * @param bool[] $openAPINullablesSetToNull
     */
    private function setOpenAPINullablesSetToNull(array $openAPINullablesSetToNull): void
    {
        $this->openAPINullablesSetToNull = $openAPINullablesSetToNull;
    }

    /**
     * Sets $this->container[$variableName] to the given data or to the given default Value; if $variableName
     * is nullable and its value is set to null in the $fields array, then mark it as "set to null" in the
     * $this->openAPINullablesSetToNull array.
     *
     * @param mixed $defaultValue
     */
    private function setIfExists(string $variableName, array $fields, $defaultValue): void
    {
        if (self::isNullable($variableName) && array_key_exists($variableName, $fields) && is_null($fields[$variableName])) {
            $this->openAPINullablesSetToNull[] = $variableName;
        }

        $this->container[$variableName] = $fields[$variableName] ?? $defaultValue;
    }
}
